using System.ComponentModel.DataAnnotations.Schema;
using System.Data.Entity.ModelConfiguration;

namespace ConsoleApplication2.Models.Mapping
{
    public class requestMap : EntityTypeConfiguration<request>
    {
        public requestMap()
        {
            // Primary Key
            this.HasKey(t => t.id);

            // Properties
            this.Property(t => t.physician)
                .HasMaxLength(6);

            this.Property(t => t.pat_id)
                .IsRequired()
                .HasMaxLength(6);

            this.Property(t => t.descr)
                .HasMaxLength(30);

            this.Property(t => t.examiner)
                .HasMaxLength(6);

            this.Property(t => t.time_col)
                .HasMaxLength(8);

            this.Property(t => t.note)
                .HasMaxLength(250);

            this.Property(t => t.admissionid)
                .IsRequired()
                .HasMaxLength(10);

            this.Property(t => t.File_Primary_Key)
                .HasMaxLength(10);

            this.Property(t => t.Bill_)
                .HasMaxLength(8);

            this.Property(t => t.Type)
                .IsFixedLength()
                .HasMaxLength(1);

            // Table & Column Mappings
            this.ToTable("request");
            this.Property(t => t.id).HasColumnName("id");
            this.Property(t => t.date).HasColumnName("date");
            this.Property(t => t.physician).HasColumnName("physician");
            this.Property(t => t.pat_id).HasColumnName("pat_id");
            this.Property(t => t.descr).HasColumnName("descr");
            this.Property(t => t.closed_req).HasColumnName("closed_req");
            this.Property(t => t.closed_reply).HasColumnName("closed_reply");
            this.Property(t => t.examiner).HasColumnName("examiner");
            this.Property(t => t.time_col).HasColumnName("time_col");
            this.Property(t => t.req_type).HasColumnName("req_type");
            this.Property(t => t.note).HasColumnName("note");
            this.Property(t => t.admissionid).HasColumnName("admissionid");
            this.Property(t => t.File_Primary_Key).HasColumnName("File Primary Key");
            this.Property(t => t.currency).HasColumnName("currency");
            this.Property(t => t.total).HasColumnName("total");
            this.Property(t => t.patpcode).HasColumnName("patpcode");
            this.Property(t => t.userid).HasColumnName("userid");
            this.Property(t => t.Bill_).HasColumnName("Bill#");
            this.Property(t => t.Type).HasColumnName("Type");
            this.Property(t => t.Department).HasColumnName("Department");
            this.Property(t => t.OrderID).HasColumnName("OrderID");
            this.Property(t => t.RQT_Abnormal).HasColumnName("RQT_Abnormal");

            // Relationships
            this.HasRequired(t => t.admision)
                .WithMany(t => t.requests)
                .HasForeignKey(d => d.admissionid);
            this.HasRequired(t => t.currency1)
                .WithMany(t => t.requests)
                .HasForeignKey(d => d.currency);
            this.HasRequired(t => t.Cust)
                .WithMany(t => t.requests)
                .HasForeignKey(d => d.pat_id);
            this.HasRequired(t => t.Name)
                .WithMany(t => t.requests)
                .HasForeignKey(d => d.userid);
            this.HasRequired(t => t.PriceLst)
                .WithMany(t => t.requests)
                .HasForeignKey(d => d.patpcode);

        }
    }
}
